-- WARNING: SANDBOX SCOREBOARD WAS BEING A DOUCHE. I SWITCHED OVER TO BASE SCOREBOARD. THIS CODE IS VERY FUCKING MESSY.

local ScoreboardTeamName 		= "Roleplayers"
local DisplayTeamsAndPlayers	= false

/*---------------------------------------------------------
   Name: gamemode:ScoreboardShow( )
   Desc: Sets the scoreboard to visible
---------------------------------------------------------*/
function GM:ScoreboardShow()
    GAMEMODE.ShowScoreboard = true
	gui.EnableScreenClicker( true )
end

/*---------------------------------------------------------
   Name: gamemode:ScoreboardHide( )
   Desc: Hides the scoreboard
---------------------------------------------------------*/
function GM:ScoreboardHide()
    GAMEMODE.ShowScoreboard = false
	gui.EnableScreenClicker( false )
end

function GM:HUDDrawScoreBoard()

    if (!GAMEMODE.ShowScoreboard) then return end
    
    if (GAMEMODE.ScoreDesign == nil) then
    
        GAMEMODE.ScoreDesign = {}
        GAMEMODE.ScoreDesign.HeaderY = 0
        GAMEMODE.ScoreDesign.Height = ScrH() / 2
    
    end
    
    local alpha = 255
    
    local xOffset = ScrW() / 10
    local yOffset = 32
    local scrWidth = ScrW()
    local scrHeight = ScrH() - 64
    local boardWidth = scrWidth - (2* xOffset)
    local boardHeight = scrHeight
    local colWidth = 75
    
    boardWidth = math.Clamp( boardWidth, 400, 600 )
    boardHeight = GAMEMODE.ScoreDesign.Height
    
    xOffset = (ScrW() - boardWidth) / 2.0
    yOffset = (ScrH() - boardHeight) / 2.0
    yOffset = yOffset - ScrH() / 4.0
    yOffset = math.Clamp( yOffset, 32, ScrH() )
    
    -- Background
    surface.SetDrawColor( 100, 150, 250, 200 )
    surface.DrawRect( xOffset, yOffset, boardWidth, GAMEMODE.ScoreDesign.HeaderY)
    
    surface.SetDrawColor( 150, 150, 150, 200 )
    surface.DrawRect( xOffset, yOffset+GAMEMODE.ScoreDesign.HeaderY, boardWidth, boardHeight-GAMEMODE.ScoreDesign.HeaderY)
    
    -- Outline
    surface.SetDrawColor( 0, 0, 0, 150 )
    surface.DrawOutlinedRect( xOffset, yOffset, boardWidth, boardHeight )
    surface.SetDrawColor( 0, 0, 0, 50 )
    surface.DrawOutlinedRect( xOffset-1, yOffset-1, boardWidth+2, boardHeight+2 )
    
    local hostname = GetHostName()
    local gamemodeName = GAMEMODE.Name .. " - " .. GAMEMODE.Author
    
    surface.SetTextColor( 255, 255, 255, 255 )
    
    if ( string.len(hostname) > 32 ) then
        surface.SetFont( "ScoreboardSub" )
    else
        surface.SetFont( "ScoreboardHead" )
    end
    
    local txWidth, txHeight = surface.GetTextSize( hostname )
    local y = yOffset + 15
    surface.SetTextPos(xOffset + (boardWidth / 2) - (txWidth/2), y)
    surface.DrawText( hostname )
    
    y = y + txHeight + 2
    
    surface.SetTextColor( 255, 255, 255, 255 )
    surface.SetFont( "ScoreboardSub" )
    local txWidth, txHeight = surface.GetTextSize( gamemodeName )
    surface.SetTextPos(xOffset + (boardWidth / 2) - (txWidth/2), y)
    surface.DrawText( gamemodeName )
    
    y = y + txHeight + 4
    GAMEMODE.ScoreDesign.HeaderY = y - yOffset
    
    surface.SetDrawColor( 0, 0, 0, 100 )
    surface.DrawRect( xOffset, y-1, boardWidth, 1)
    
    surface.SetDrawColor( 255, 255, 255, 20 )
    surface.DrawRect( xOffset + boardWidth - (colWidth*1), y, colWidth, boardHeight-y+yOffset )
    
    surface.SetDrawColor( 255, 255, 255, 20 )
    surface.DrawRect( xOffset + boardWidth - (colWidth*3), y, colWidth, boardHeight-y+yOffset )
    
    
    surface.SetFont( "ScoreboardText" )
    local txWidth, txHeight = surface.GetTextSize( "W" )
    
    surface.SetDrawColor( 0, 0, 0, 100 )
    surface.DrawRect( xOffset, y, boardWidth, txHeight + 6 )

    y = y + 2
    
	
	
    surface.SetTextPos( xOffset + 16,                                 y)    surface.DrawText("#Name")
	surface.SetTextPos( xOffset + boardWidth - (colWidth*5.5) + 8,	  y)	surface.DrawText("Steam Name")
    surface.SetTextPos( xOffset + boardWidth - (colWidth*2.8) + 8,    y)    surface.DrawText("Lusion ID")
    surface.SetTextPos( xOffset + boardWidth - (colWidth*1.8) + 8,    y)    surface.DrawText("Murders")
    surface.SetTextPos( xOffset + boardWidth - (colWidth*0.9) + 8,    y)    surface.DrawText("#Ping")
    
	
	
    y = y + txHeight + 4

    local yPosition = y
	

	if DisplayTeamsAndPlayers and DisplayTeamsAndPlayers == true then
		
		for k,v in pairs(Lusion_Teams) do
		
			ScoreboardTeamName = "Job " .. v.menuName .. " - " .. team.NumPlayers(k) .. " Player(s)"
		
		end
	end
			surface.SetFont( "ScoreboardText" )
			surface.SetTextColor( 0, 0, 0, 255 )
        
			txWidth, txHeight = surface.GetTextSize( ScoreboardTeamName )
			surface.SetDrawColor( 100, 200, 50, 255 )
			surface.DrawRect( xOffset+1, yPosition, boardWidth-2, txHeight + 4)
			yPosition = yPosition + 2
			surface.SetTextPos( xOffset + boardWidth/2 - txWidth/2, yPosition )
			surface.DrawText( ScoreboardTeamName )
			yPosition = yPosition + 2
                        

        
			yPosition = yPosition + txHeight + 2
        
			for k2, v2 in pairs(player.GetAll()) do   
            
				surface.SetDrawColor( 220, 50, 90, 50 )
				surface.DrawRect( xOffset+1, yPosition, boardWidth - 2, txHeight + 2)
				surface.SetTextColor( 220, 50, 90, 255 )
            
				-- these are displaying the actual data rather than the headers.
			
				local px, py = xOffset + 16, yPosition
				local textcolor = Color( 220, 50, 90, 190 )
				local shadowcolor = Color( 0, 0, 0, 190 * 0.8 )
			
				draw.SimpleText( v2:Nick(), "ScoreboardText", px+1, py+1, shadowcolor )
				draw.SimpleText( v2:Nick(), "ScoreboardText", px, py, textcolor )
				
				px = xOffset + boardWidth - (colWidth*5.8) + 8
				draw.SimpleText( v2:RealName(), "ScoreboardText", px+1, py+1, shadowcolor )
				draw.SimpleText( v2:RealName(), "ScoreboardText", px, py, textcolor )
            
				px = xOffset + boardWidth - (colWidth*2.8) + 8            
				draw.SimpleText( v2:GetNWInt("lusion_id"), "ScoreboardText", px+1, py+1, shadowcolor )
				draw.SimpleText( v2:GetNWInt("lusion_id"), "ScoreboardText", px, py, textcolor )
            
				px = xOffset + boardWidth - (colWidth*1.8) + 8            
				draw.SimpleText( v2:Frags(), "ScoreboardText", px+1, py+1, shadowcolor )
				draw.SimpleText( v2:Frags(), "ScoreboardText", px, py, textcolor )
            
				px = xOffset + boardWidth - (colWidth*0.9) + 8            
				draw.SimpleText( v2:Ping(), "ScoreboardText", px+1, py+1, shadowcolor )
				draw.SimpleText( v2:Ping(), "ScoreboardText", px, py, textcolor )
            
				--surface.DrawText( plinfo.Name )
				--surface.SetTextPos( xOffset + 16 + 2, yPosition + 2 )
				--surface.SetTextColor( 0, 0, 0, 200 )
				--surface.DrawText( plinfo.Name )

				--surface.SetTextPos( xOffset + boardWidth - (colWidth*3) + 8, yPosition )
				--surface.DrawText( plinfo.Frags )

				--surface.SetTextPos( xOffset + boardWidth - (colWidth*2) + 8, yPosition )
				--surface.DrawText( plinfo.Deaths )

				--surface.SetTextPos( xOffset + boardWidth - (colWidth*1) + 8, yPosition )
				--surface.DrawText( plinfo.Ping )

				yPosition = yPosition + txHeight + 3
				end
    --end
    
    yPosition = yPosition + 8
    
    GAMEMODE.ScoreDesign.Height = (GAMEMODE.ScoreDesign.Height * 2) + (yPosition-yOffset)
    GAMEMODE.ScoreDesign.Height = GAMEMODE.ScoreDesign.Height / 3
    
end

